package com.shopcart.entity;

import java.util.Collection;
import java.util.HashSet;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

@Entity
@Table(name = "SHOP_CART")
public class Cart implements java.io.Serializable {

	private static final long serialVersionUID = -7739931496351140920L;

	@TableGenerator(name = "cartIdGen", table = "SHOP_SEQUENCE_GENERATOR", pkColumnName = "GEN_KEY", valueColumnName = "GEN_VALUE", pkColumnValue = "CART_ID", initialValue = 1, allocationSize = 1)
	@Id
	@GeneratedValue(strategy = GenerationType.TABLE, generator = "cartIdGen")
	@Column(name = "CART_ID", nullable = false)
	private Long id;

	@OneToMany
	private Collection<CartItem> items = new HashSet<CartItem>();

	@Column(name = "CART_CUSTOMER")
	private Customer customer;

	/** Creates a new instance of Customer */
	public Cart() {
	}

	public Cart(Long id, Collection<CartItem> items, Customer customer) {
		this.id = id;
		this.items = items;
		this.customer = customer;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Collection<CartItem> getItems() {
		return items;
	}

	public void setItems(Collection<CartItem> items) {
		this.items = items;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}
}